import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

import Layout from "@/layouts";

// * ==================== 静态 框架内路由 ====================
const staticRoutesIn = [
  {
    path: "/",
    component: Layout,
    redirect: { name: "Index" },
    children: [
      {
        path: "",
        name: "Index",
        component: () => import("@/views/index"),
      },
    ],
  },
];

// * ==================== 静态 框架外路由 ====================
const staticRoutesOut = [
  {
    path: "/login",
    component: () => import("@/views/basic/login"),
  },
  {
    path: "/register",
    component: () => import("@/views/basic/register"),
  },
  {
    path: "/404",
    component: () => import("@/views/basic/404"),
  },
  {
    path: "*",
    component: () => import("@/views/basic/404"),
  },
];

// * ==================== 动态路由 ====================
const dynamicRoutes = [
  {
    path: "/system",
    component: Layout,
    children: [
      {
        path: "/system/menu",
        name: "SystemMenu",
        component: () => import("@/views/system/menu/index.vue"),
      },
      {
        path: "/system/notice",
        name: "SystemNotice",
        component: () => import("@/views/system/notice/index.vue"),
      },
    ],
  },
  {
    path: "/permission",
    component: Layout,
    children: [
      {
        path: "/permission",
        name: "Permission",
        component: () => import("@/views/permission/index.vue"),
      },
    ],
  },
  {
    path: "/dashboard",
    component: Layout,
    children: [
      {
        path: "/dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index.vue"),
      },
    ],
  },
];

const routes = [...staticRoutesIn, ...staticRoutesOut, ...dynamicRoutes];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  next();
});

router.afterEach((to, from) => {});

export default router;
